package com.xiaozhichao.gateway001.config;

import org.springframework.cloud.gateway.filter.factory.HystrixGatewayFilterFactory;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RouteConfig {

    @Bean
    public RouteLocator myRoutes(RouteLocatorBuilder builder) {
        return builder.routes()
                .route(
                        predicateSpec -> predicateSpec.path("/get")
                                .filters(
                                        gatewayFilterSpec -> gatewayFilterSpec.addRequestHeader("hello", "World")
                                )
                                .uri("http://httpbin.org:80")
                )
                .route(
                        predicateSpec -> predicateSpec.host("*.hystrix.com")
                                .filters(
                                        gatewayFilterSpec -> gatewayFilterSpec.hystrix(config -> config.setName("mycmd"))
                                )
                                .uri("http://httpbin.org:80")
                )
                .build();
    }

}
